<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">

	<div class="container-div ui-layout-center">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="plan-config-form">
					<input type="hidden" id="deptId" name="deptId">
	                <input type="hidden" id="parentId" name="parentId">
					<div class="select-list">
						<ul>
							<li>
								计划名称：<input type="text" name="planCfgName"/>
							</li>
							<li>
								部门名称：<input type="text" name="planDeptName"/>
							</li>
							<li class="select-time">
								<label>更新时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
						</ul>
						<ul style="text-align:right">
							<li>
								<!--<button class="btn btn-success btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</button>-->
								<a class="btn btn-success btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-success btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
	        	<button  class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="plan:config:add">
	                <i class="fa fa-plus"></i> 新增
	            </button>
	             <a class="btn btn-success btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="plan:config:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
	            <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="plan:config:remove">
	                <i class="fa fa-remove"></i> 删除
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<div th:include="include :: footer"></div>
	<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('plan:config:edit')}]];
		var removeFlag = [[${@permission.hasPermi('plan:config:remove')}]];
		var downloadFlag = [[${@permission.hasPermi('plan:config:download')}]];
		var detailFlag = [[${@permission.hasPermi('plan:detail:list')}]];
		var publishFlag = [[${@permission.hasPermi('plan:config:publish')}]];
		var cstrFlag = [[${@permission.hasPermi('plan:config:constraint')}]];
		var datas = [[${@dict.getType('plan_release_status')}]];
		var prefix = ctx + "plan/config";

		$(function() {
			$('body').layout({ west__size: 185 });
			queryPlanList();
		});

		function queryPlanList() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        downloadUrl: prefix + "/download",
		        detailUrl: prefix + "/detail",
		        publishUrl: prefix + "/publish",
		        cancelUrl: prefix + "/cancel",
		        sortName: "planCfgUpdateTime",
		        sortOrder: "desc",
		        modalName: "计划配置",
		        search: false,
		        showExport: false,
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'planCfgId',
		            title: '计划ID'
		        },
		        {
		            field: 'planCfgName',
		            title: '计划名称',
		            sortable: true
		        },
		        <!--{-->
		            <!--field: 'planCfgDeptId',-->
		            <!--title: '部门ID'-->
		        <!--},-->
		        {
		            field: 'planDeptName',
		            title: '部门名称'
		        },
		        {
		            field: 'planCfgFlowName',
		            title: '流程名称'
		        },
		        {
		            field: 'planCfgStatus',
		            title: '状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(datas, value);
		            }
		        },
		        {
		            field: 'planCfgPassScore',
		            title: '通过分数'
		        },
		        {
		            field: 'planCfgStartTime',
		            title: '计划启动时间'
		        },
		        {
		            field: 'planCfgEndTime',
		            title: '计划结束时间'
		        },
		        {
		            field: 'planCfgUpdateTime',
		            title: '计划更新时间',
		            sortable: true
		        },
		        {
		            field: 'userName',
		            title: '更新人'
		        },
		        {
		            title: '操作',
		            align: '',
		            width:"330",
		            formatter: function(value, row, index) {
		                var actions = [];
		                var status = row.planCfgStatus;
		                if(status == '0'){
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" style="margin:3px;" href="#" onclick="$.operate.edit(\'' + row.planCfgId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
							actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" style="margin:3px;" href="#" onclick="detail(\'' + row.planCfgId + '\')"><i class="fa fa-edit"></i>详情</a>');
							actions.push('<a class="btn btn-success btn-xs ' + publishFlag + '" style="margin:3px;" href="#" onclick="publish(\'' + row.planCfgId + '\')"><i class="fa fa-edit"></i>发布</a>');
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" style="margin:3px;" href="#" onclick="$.operate.remove(\'' + row.planCfgId + '\')"><i class="fa fa-remove"></i>删除</a> ');
		                }
		                else if(status == '1'){
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" style="margin:3px;" href="#" onclick="cancel(\'' + row.planCfgId + '\')"><i class="fa fa-edit"></i>撤销发布</a> ');
							actions.push('<a class="btn btn-success btn-xs ' + downloadFlag + '" style="margin:3px;" href="#" onclick="download1(\'' + row.planCfgId + '\')"><i class="fa fa-edit"></i>下载模板</a>');
							actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" style="margin:3px;" href="#" onclick="detail(\'' + row.planCfgId + '\')"><i class="fa fa-edit"></i>详情</a>');

		                }
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		}

		/*计划配置详细*/
		function detail(planCfgId) {
		    var url = prefix + '/detail/' + planCfgId;
		    createMenuItem(url, "项目配置");
		}

		function publish(id) {
			if ($.common.isNotEmpty(id)){
				var url = $.table._option.publishUrl.replace("{id}", id);
				$.modal.confirm("确定发布该条" + $.table._option.modalName + "吗？", function() {
					var data = { "id": id };
					$.operate.submit(url, "post", "json", data);
				});
			}
		}

		function constraint(planCfgId) {
		    var url = prefix + '/constraint/' + planCfgId;
		    createMenuItem(url, "计划约束");
		}

		function cancel(id) {
			if ($.common.isNotEmpty(id)){
				var url = $.table._option.cancelUrl.replace("{id}", id);
				$.modal.confirm("确定撤消该条" + $.table._option.modalName + "吗？", function() {
					var data = { "id": id };
					$.operate.submit(url, "post", "json", data);
				});
			}
		}

		function download1(id) {
			if ($.common.isNotEmpty(id)) {
				  $.modal.loading("正在导出数据，请稍后...");
				  var downloadPara={"id":id}
				  $.post($.table._option.downloadUrl,downloadPara, function(result) {
					  if (result.code == web_status.SUCCESS) {
						  window.location.href = ctx + "common/templateDownload?filePath=" + result.msg + "&delete=" + false;
					  } else {
						  $.modal.alertError(result.msg);
					  }
					  $.modal.closeLoading();
				  });
			} else {
				$.modal.alertWarning("没有选择记录");
			}
		}

	</script>
</body>
</html>